home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 4 April 1997
- //
- // Procedure Name:
- // performSubdAutoProj
- //
- // Description:
- //
- //
- // Input Arguments:
- // $option : Whether to set the options to default values.
- // Return Value:
- // command string iff $option==2
- //
-
- //
- // Initialize optionVars for subdAutoProj:
- // Color, Texture, Vertex
- //
- proc setOptionVars (
- string $prefix,
- int $forceFactorySettings,
- string $vars[]
- )
- {
- string $varName;
-
- // Must match $vars
- int $intValues[]= { 3, 1, 1, 2, 0 };
-
- for ( $i = size($vars) ; $i-- ; )
- {
- $varName = ($prefix + $vars[$i]);
- if ($forceFactorySettings || !`optionVar -exists $varName`)
- optionVar -intValue $varName $intValues[$i];
- }
-
- $varName = ($prefix + "eg");
- if ($forceFactorySettings || !`optionVar -exists $varName`)
- optionVar -floatValue $varName .2;
-
- /*
- // Also add the map name
- $varName = ($prefix + "uvSetName");
- if ($forceFactorySettings || !`optionVar -exists $varName`)
- optionVar -stringValue $varName "uvSet1";
- */
- }
-
- global proc performSubdAutoProjSetup (string $parent, int $forceFactorySettings)
- {
- string $prefix = "subdAutoProj";
- // string $intVars[] ={"p", "o", "sc", "l", "cm"};
- string $intVars[] ={"p", "o", "sc", "l"};
- string $varName;
- float $presets[] = {.1, .2, .4, .8, 1.6, 3.2};
- int $i;
-
- setOptionVars($prefix, $forceFactorySettings, $intVars);
- setParent $parent;
-
- $varName = ($prefix + $intVars[0]);
- optionMenuGrp -e -sl `optionVar -query $varName` $varName;
-
- $varName = ($prefix + $intVars[1]);
- radioButtonGrp -e -sl (`optionVar -query $varName`+1) $varName;
-
- $varName = ($prefix + $intVars[2]);
- radioButtonGrp -e -sl (`optionVar -query $varName`+1) $varName;
-
- $varName = ($prefix + $intVars[3]);
- radioButtonGrp -e -sl `optionVar -query $varName` $varName;
-
- $varName = ($prefix + "eg");
- float $fval = `optionVar -q $varName`;
- floatSliderGrp -e -v $fval $varName;
-
- // See if the value corresponds to one of the presets.
- $varName = ($prefix + "egPresets");
- optionMenuGrp -e -sl 1 $varName;
- for ($i = size($presets) ; $i-- ; )
- {
- if ($fval == $presets[$i])
- {
- optionMenuGrp -e -sl ($i+2) $varName;
- break;
- }
- }
-
- /*
- $varName = ($prefix + $intVars[4]);
- int $val = `optionVar -query $varName`;
- checkBoxGrp -edit -value1 $val $varName;
- $varName = ($prefix + "uvSetName");
- textFieldGrp -edit -en $val -tx `optionVar -q $varName` $varName;
- */
- }
-
- global proc performSubdAutoProjCallback (string $parent, int $doIt)
- {
- string $prefix = "subdAutoProj";
- string $intVars[] ={"p", "o", "sc", "l", "cm"};
- string $varName;
-
- setParent $parent;
-
- $varName = ($prefix + $intVars[0]);
- optionVar -intValue $varName `optionMenuGrp -q -sl $varName`;
-
- $varName = ($prefix + $intVars[1]);
- optionVar -intValue $varName (`radioButtonGrp -q -sl $varName`-1);
-
- $varName = ($prefix + $intVars[2]);
- optionVar -intValue $varName (`radioButtonGrp -q -sl $varName`-1);
-
- $varName = ($prefix + $intVars[3]);
- optionVar -intValue $varName `radioButtonGrp -q -sl $varName`;
-
- /*
- $varName = ($prefix + $intVars[4]);
- optionVar -intValue $varName `checkBoxGrp -query -value1 $varName`;
-
- $varName = ($prefix + "uvSetName");
- optionVar -stringValue $varName `textFieldGrp -query -tx $varName`;
- */
-
- $varName = ($prefix + "eg");
- optionVar -floatValue $varName `floatSliderGrp -q -v $varName`;
-
- if ($doIt)
- {
- performSubdAutoProj 0;
- addToRecentCommandQueue "performSubdAutoProj 0" "SubdAutoProj";
- }
- }
-
- global proc subdAutoSpacingPresets()
- {
- int $item = `optionMenuGrp -q -sl "subdAutoProjegPresets"`-2;
- float $presets[] = {.1, .2, .4, .8, 1.6, 3.2};
-
- if ($item>=0 && $item<6)
- floatSliderGrp -e -v $presets[$item] "subdAutoProjeg";
- }
-
- proc subdAutoProjOptions (string $prefix, string $intVars[])
- {
- string $commandName = "performSubdAutoProj";
- string $callback = ($commandName + "Callback");
- string $setup = ($commandName + "Setup");
- string $varName;
-
- string $layout = getOptionBox();
- setParent $layout;
- setUITemplate -pushTemplate DefaultTemplate;
- waitCursor -state 1;
-
- string $parent = `columnLayout -adjustableColumn 1`;
-
- $varName = ($prefix + $intVars[0]);
-
- optionMenuGrp -l "Planes" $varName;
- menuItem -l "4";
- menuItem -l "5";
- menuItem -l "6";
- menuItem -l "8";
- menuItem -l "12";
- setParent -m ..;
-
- $varName = ($prefix + $intVars[1]);
- radioButtonGrp -l "Optimize" -nrb 2
- -l1 "Less Distortion"
- -l2 "Fewer Pieces" $varName;
-
- separator;
-
- $varName = ($prefix + $intVars[3]);
- $gapName = ($prefix + "eg");
- $menuName = ($prefix + "egPresets");
- string $grayCmd =
- "{ int $tmp = `radioButtonGrp -q -sl "+$varName + "` == 2;" +
- " floatSliderGrp -e -en $tmp "+$gapName+";" +
- " optionMenuGrp -e -en $tmp "+$menuName+";}";
- radioButtonGrp -l "Layout" -nrb 2 -cc $grayCmd
- -l1 "Along U"
- -l2 "Into Square" $varName;
-
- $varName = ($prefix + $intVars[2]);
- radioButtonGrp -l "Scale" -nrb 3
- -l1 "None"
- -l2 "Uniform"
- -l3 "Stretch to Square" $varName;
-
- separator;
-
- optionMenuGrp -l "Spacing Presets" -cc subdAutoSpacingPresets $menuName;
- menuItem -l " Custom";
- menuItem -l "1024 Map";
- menuItem -l " 512 Map";
- menuItem -l " 256 Map";
- menuItem -l " 128 Map";
- menuItem -l " 64 Map";
- menuItem -l " 32 Map";
- setParent -m ..;
-
- string $cmd = ("optionMenuGrp -e -sl 1 " + $menuName);
- floatSliderGrp -l "Percentage Space" -min 0 -max 5 -cc $cmd $gapName;
-
- /*
- separator;
- separator;
-
- $varName = ($prefix + $intVars[4]);
- $textName = ($prefix + "uvSetName");
- string $grayCmd =
- "{ int $tmp = `checkBoxGrp -q -v1 "+$varName + "`;" +
- " textFieldGrp -e -en $tmp "+$textName+";}";
- checkBoxGrp -label1 "Create New UV Set" -cc $grayCmd $varName;
- textFieldGrp -label "UV Set Name: " $textName;
- */
-
- waitCursor -state 0;
- setUITemplate -popTemplate;
-
- string $applyBtn = getOptionBoxApplyBtn();
- button -edit -label "Project"
- -command ($callback + " " + $parent + " " + 1) $applyBtn;
- string $saveBtn = getOptionBoxSaveBtn();
- button -edit
- -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
- $saveBtn;
- string $resetBtn = getOptionBoxResetBtn();
- button -edit
- -command ($setup + " " + $parent + " " + 1) $resetBtn;
-
- setOptionBoxTitle("Subdiv Automatic Mapping Options");
-
- setOptionBoxHelpTag( "SubdivAutomaticMapping" );
-
- eval (($setup + " " + $parent + " " + 0));
-
- showOptionBox();
- }
-
- /*
- proc string createCurrentShader ()
- {
- global string $subdTextureColorShader;
- string $shader;
- string $shaderType="lambert";
- string $textureName="checker";
- if (`optionVar -q subdCreateShaderWithMapping` == 0)
- return "";
- string $shader=`evalEcho "sets -n texturedFacets -em -r true -nss true"`;
- if ($shader != "") {
- evalEcho ("partition -e -addSet renderPartition " + $shader);
- string $shad[];
- if ($subdTextureColorShader != "")
- $shad=`ls -showType $subdTextureColorShader`;
- if ($subdTextureColorShader == "" || size($shad) == 0) {
- string $texture[]=`ls -showType defaultPolygonTexture`;
- if (size($texture) == 0)
- $texture[0]=`evalEcho ("shadingNode -asTexture "
- + $textureName + " -n defaultPolygonTexture")`;
- $subdTextureColorShader=`evalEcho ("shadingNode -asShader "
- + $shaderType + " -n defaultPolygonShader")`;
- evalEcho ("connectAttr " + $texture[0] + ".outColor "
- + $subdTextureColorShader + ".color");
- // creating a node selects it: we don't want that...
- select -d $texture[0] $subdTextureColorShader;
- }
- $shad=`ls -showType $subdTextureColorShader`;
- if ($subdTextureColorShader != "" && size($shad) != 0)
- evalEcho ("connectAttr -f " + $subdTextureColorShader + ".outColor "
- + $shader + ".surfaceShader");
- else warning "Could not create the default polygons shader";
- } else warning "Could not create a new set to hold the faces.";
- return $shader;
- }
- */
-
- proc string getFacesToProject()
- {
- // Returns a string representing the currently applicable
- // selection items. ie. if a subdiv surface is selected,
- // then this returns a string containing its base faces.
- // All base faces can be projected onto.
- //
- // If subd faces are already selected, then return nothing.
- // If only subd objects are selected, then return string with all
- // base faces.
-
- string $result = "";
-
- // There are already subd faces selected, just return
- //
- string $subdFaces[] = `filterExpand -sm 38`;
-
- // Find out if there are any subdivision surfaces selected
- //
- int $numSubdivs = 0;
- string $selectedSubdivs[];
- string $allSubds[] = `filterExpand -ex 1 -sm 68`;
-
- // If there are subd faces AND subd objects, then
- // display warning
- //
- if( size($subdFaces) > 0 ) {
- if( size($allSubds) > 0 ) {
- warning(" Only the selected subdiv surface faces will be projected. All selected subdiv surfaces will be ignored.");
- }
- return $result;
- }
-
- for ( $obj in $allSubds ) {
- $numSubdivs ++;
- $selectedSubdivs[$numSubdivs-1] = $obj;
- };
-
- if( $numSubdivs > 0 ) {
- // create a string of subdiv faces from the selected subdivs
- for ( $subd in $selectedSubdivs) {
- string $tmp = "ls ";
- $tmp += $subd;
- $tmp += ".smf[\"*\"][\"*\"]" ;
- $tmp += " ;";
- string $allFaces[] = eval( $tmp );
- for( $face in $allFaces ) {
- $result += " ";
- $result += $face;
- }
- }
- }
- return $result;
- }
-
- global proc string performSubdAutoProj (int $option)
- {
- string $prefix = "subdAutoProj";
- // string $intVars[] ={"p", "o", "sc", "l", "cm"};
- string $intVars[] ={"p", "o", "sc", "l"};
- string $cmd="";
-
- switch ($option)
- {
- case 0:
-
- // If nothing selected, then return
- //
- string $sel[] = `ls -sl`;
- if( size($sel) == 0 ) {
- warning(" Subdiv Surfaces Texture projection works only on subdiv surfaces or subdiv surface faces.");
- return $cmd;
- }
-
- string $varName;
- int $ival;
- setOptionVars($prefix, false, $intVars);
- $cmd = "subdAutoProjection";
- for ( $i = size($intVars) ; $i-- > 1; )
- {
- $varName = ($prefix + $intVars[$i]);
- $ival = `optionVar -query $varName`;
- $cmd = $cmd + " -" + $intVars[$i] + " " + $ival;
- }
-
- $varName = ($prefix + $intVars[0]);
- $ival = `optionVar -query $varName`;
- int $numVal[] = {4, 5, 6, 8, 12};
- $cmd = $cmd + " -" + $intVars[0] + " " + $numVal[$ival-1];
-
- /*
- // Code to get value of uvSetName if createNew UVSet is toggled on..
- //
- $varName = ($prefix + $intVars[4]);
- $ival = `optionVar -query $varName`;
- if ($ival)
- {
- $varName = ($prefix + "uvSetName");
- string $sval = `optionVar -query $varName`;
- if ($sval != "")
- $cmd = $cmd + " -uvSetName " + $sval;
- }
- */
-
- $varName = ($prefix + "eg");
- float $fval = `optionVar -query $varName`;
- $cmd = $cmd + " -ps " + $fval;
-
- // Convert everything to subd faces, if necessary
- //
- string $selectionToProject = getFacesToProject();
- $cmd += $selectionToProject;
-
- // polyPerformAction $cmd "f" 0;
- string $result[] = `eval $cmd`;
-
- /*
- string $totalSel[] = `ls -sl`;
- string $shader=`createCurrentShader`;
- // Update shader's set.
- if( $shader != "") {
- $cmd=("sets -e -fe " + $shader);
- int $i;
- for($i=0; $i < size($totalSel); $i++)
- $cmd=($cmd + " " + $totalSel[$i]);
- evalEcho $cmd;
- evalEcho `select -r $totalSel`;
- }
- */
-
- // Set selection
-
- break;
-
- case 1:
- subdAutoProjOptions($prefix, $intVars);
- break;
- case 2:
- $cmd="performSubdAutoProj 0";
- break;
- }
-
- // Return the name of the new projection node
- //
- return $result[0];
- }
-